package com.java46.struts2.admin.service;

import com.java46.struts2.admin.constant.AdminConstant;
import com.java46.struts2.admin.dao.AdminDao;
import com.java46.struts2.base.exception.BusinessException;
import com.java46.struts2.base.util.SqlUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName AdminService
 * @Description TODO
 * @Author Administrator
 * @Date 2018/7/22 0022 19:48
 * @Vcrsion 1.0
 **/
public class AdminService {

    /**
     * @Author xiaobo
     * @Description //管理员登录
     * @Date 19:58 2018/7/22 0022
     * @Param [name, pwd]
     * @return void
     */
    public static void queryAdmin(String name,String pwd,HttpServletRequest request){
        if(name==null||name.trim().equals("")||pwd==null||pwd.trim().equals("")){
            throw new BusinessException("管理员信息不能为空");
        }
        String adminpwd=SqlUtils.md5encrypt(pwd);
        List list = AdminDao.queryAdmin(name, adminpwd);
        if (list.isEmpty()){
            throw  new BusinessException("该管理员不存在");
        }
        request.getSession().setAttribute(AdminConstant.ADMIN_SESSION_KEY,list.get(0));

    }
}
